﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Website.Action
{
    public class AceModel_Task : IAceModel
    {
        private LiteFramework.Model.Task _source = null;
        public AceModel_Task(LiteFramework.Model.Task source)
        {
            BaseFramework.DataValid.IsNull(source, "source");

            //this.id = task.Id.ToString();
            //this.group = task.Group;
            //this.code = task.Code;
            //this.name = task.Name;
            //this.description = task.Remark;

            this._source = source;
        }

        #region Property
        public string id { get; set; }
        public string group { get; set; }
        public string code { get; set; }
        public string name { get; set; }
        public string description { get; set; }
        #endregion

        public string ToJsonString()
        {
            return new Json()
                    .Add("id", this._source.Id)
                    .Add("group", this._source.Group)
                    .Add("code", this._source.Code)
                    .Add("name", this._source.Name)
                    .Add("description", this._source.Description)
                    .ToJsonString();
        }

        public static IEnumerable<AceModel_Task> ParseList(IEnumerable<LiteFramework.Model.Task> sources)
        {
            if (sources == null || sources.Count() == 0) throw new ArgumentException("至少包含一项", "sources");
            foreach (var item in sources)
            {
                yield return new AceModel_Task(item);
            }
        }
    }
}